import oUtils from './fn.oUtils.js';
function PageRequest() {
    this.socket = null;
}
PageRequest.prototype = {
    constructor: PageRequest,
    socketInit: function () {
        this.socket = oUtils.socket({
            url: "pageRequest",
            error: function (err) {
                console.log(err);
            }
        });
    },
    //live video和social account：更新R状态
    taskInfo_l: function (recArr) {
        var socket = this.socket;
        var taskInfoMsg = {
            type: "taskInfo",
            sourceStr: '',
            programStr: recArr.join(",")
        };
        this.socket.send({
            message: taskInfoMsg,
            time: 1000,
            key: 'taskInfo1',
            success: function (response) {
                if (!response.taskInfo) return;
                var data = JSON.parse(response.taskInfo);
                fn_updateTRStatusInfo(data[0].rInfo);
                var receiverArray = [];
                $.each(rData, function (idx, itm) {
                    var peerId = itm.peerId;
                    var name = itm.name;
                    //不要cloudr的
                    if (name != "CloudR") {
                        receiverArray.push(itm.peerId);
                    }
                })
                var taskInfoMsg = {
                    type: "taskInfo",
                    module: "taskInfo1",
                    sourceStr: '',
                    programStr: receiverArray.join(",")
                };
                socket.sendMsgs["taskInfo1"].message = taskInfoMsg;
            }
        })
    },
    shareNum_l: function () {//live video和social account:更新R的分享状态
        var receiverArrays = [];
        $.each(rData, function (idx, itm) {
            var peerId = itm.peerId;
            receiverArrays.push(itm.peerId);
        })
        var socket = this.socket;
        var shareNumMsg = {
            type: "shareNum",
            ridList: receiverArrays.join(",")
        }
        this.socket.send({
            message: shareNumMsg,
            time: 1000,
            key: 'shareNum1',
            success: function (response) {
                // console.log("当前状态:");
                //console.log(response);
                var receiverArray = [];
                $.each(rData, function (idx, itm) {
                    var peerId = itm.peerId;
                    receiverArray.push(itm.peerId);
                })
                var shareNumMsg = {
                    type: "shareNum",
                    module: "shareNum1",
                    ridList: receiverArray.join(",")
                }
                socket.sendMsgs["shareNum1"].message = shareNumMsg;
                if (!response.shareNum) {//无账号分享
                    nickNameArry = [];
                    $("#liveVideoList").children(".liveVideo-item").attr("data-encoderIndex", 0);
                    $(".shareIcon").find(".icon-socialMeida").removeClass("active");
                    $(".liveVideo-item").find(".shareCircle").hide();
                    $(".infoShare").html(switchLangObj.i18n_No);
                    $(".inforType .icon-socialMeida").removeClass("active");
                    return;
                }
                var data = JSON.parse(response.shareNum)
                getShareNumL(data);
            }
        })
    },
    shareRInfo: function () {//新添加的socket 循环R的id使用socket刷新R列表的信息
        var socket = this.socket;
        var peerIdList = "";
        var shareRInfoObj = getParam();
        socket.send({
            message: shareRInfoObj,
            time: 5000,
            key: 'shareRInfo',
            canSendMore: true,
            isMoreSend: true,
            success: function (response) {
                var shareRInfoObjNew = getParam();
                socket.sendMsgs["shareRInfo"].message = shareRInfoObjNew;
                var data = JSON.parse(response.shareInfo);
                // console.log(data)
                if (data.errorInfo) {
                    var result = $.parseJSON(data.errorInfo);
                    for (var i in result) {
                        var key = i;
                        var maxCopier = $.parseJSON(result[i]).MaxCopierCount;
                        $("#" + key).attr("data-maxCopier", maxCopier);
                    }
                }
            }
        }, true, true);
    }
}

export {
    PageRequest
};